package main

import (
	"flag"
	"log"
	"strings"

	"gitee.com/dark.H/DataDash/in"
)

var (
	FromSource  string
	TableName   string
	onlyDesc    bool
	QueryString string
)

func main() {
	flag.StringVar(&FromSource, "s", "", "source schema like: mysql:// | xlsx:// | text:// ")
	flag.StringVar(&TableName, "t", "", "table name set for -> mysql/sqlite3 | xlsx  ")
	flag.BoolVar(&onlyDesc, "H", false, "only desc")
	flag.Parse()
	if FromSource == "" {
		in.SearchByUI(func(bottle in.BottleInterface, oper *in.Oper) {
			log.Println(oper.Filter)
			d := bottle.Query(oper)
			in.ColorT(d)
		}, func(err error) {
			log.Println("Err deal :", err)
		})
		return
	}
	tail := strings.Join(flag.Args(), " ")
	g := in.LineToDict(tail)
	if len(g) > 0 {
		in.ColorD(g)
	}
	bottle, err := in.AutoBottle(in.ParsePath(FromSource))
	if err != nil {
		log.Fatal(err)
	}
	if onlyDesc {
		s := bottle.Desc(in.OperWith(TableName))
		in.ColorS(s...)
	} else {
		d := bottle.Query(in.OperWith(TableName).Grep(g))
		in.ColorT(d)
	}

}
